package cn.wolfcode.cloud.shop.advice;


import cn.wolfcode.cloud.shop.resp.MemberServerCodeMsg;
import cn.wolfcode.cloud.shop.resp.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author Administrator
 */
@RestControllerAdvice
public class MemberExceptionAdvice extends CommonExceptionAdvice{


    private final Logger logger = LoggerFactory.getLogger("MEMBER_EXCEPTION_ADVICE");


    @ExceptionHandler(BindException.class)
    public Result<?> argumentExceptionHandler(BindException e){
        logger.warn("参数异常:",e);
        ObjectError objectError = e.getAllErrors().get(0);
        String realMsg = objectError.getDefaultMessage();
        return Result.error(MemberServerCodeMsg.ARGUMENTS_ERROR.fillArgs(realMsg));
    }
}
